package com.shopping.system.service.impl;

import com.shopping.common.entity.Good;
import com.shopping.common.entity.GoodSku;
import com.shopping.common.entity.vo.GoodSecondSkillVo;
import com.shopping.common.result.Result;
import com.shopping.system.mapper.SystemMapper;
import com.shopping.system.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class SystemServiceImpl implements SystemService {

    @Autowired
    SystemMapper systemMapper;

    /**
     * 查找此时段开始的秒杀活动
     * @return
     */
    @Override
    public Result<List<GoodSecondSkillVo>> findVoliadSecondSkillGood() {
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:00:00");
        String format1 = format.format(date);
        Date date1 = new Date(format1);
        List<GoodSecondSkillVo> list = systemMapper.findVoliadSecondSkillGood(date1);
        return Result.success(list);
    }

    /**
     * 查找可同步商品
     * @return
     */
    @Override
    public List<Good> findVoliadAddEsGood() {
        return systemMapper.findVoliadAddEsGood();
    }

    /**
     * 修改同步商品信息
     * @param list
     */
    @Override
    public void updateAddedGood(List<Good> list) {
        systemMapper.updateAddedGood(list);
    }

    /**
     * 查找所有商品
     * @return
     */
    @Override
    public List<Good> findGood() {
        return systemMapper.findGood();
    }

    /**
     * 查找所有商品sku
     * @return
     */
    @Override
    public List<GoodSku> findGoodSku() {
        return systemMapper.findGoodSku();
    }

    /**
     * 查找商品详情
     * @param id
     * @return
     */
    @Override
    public Result<GoodSecondSkillVo> findGoodMore(String id) {
        GoodSecondSkillVo goodMore = systemMapper.findGoodMore(id);
        return Result.success(goodMore);
    }

    /**
     * 加入购物车
     * @param buyNum
     * @param goodSkuChecked
     * @param id
     */
    @Override
    public void addShopCar(Integer buyNum, Integer goodSkuChecked, Integer id) {
     systemMapper.addShopCar(buyNum,goodSkuChecked,id);
    }

    /**
     * 是否加入该商品
     * @param goodSkuChecked
     * @return
     */
    @Override
    public Integer findIsAddGood(Integer goodSkuChecked) {
        return systemMapper.findIsAddGood(goodSkuChecked);
    }

    /**
     * 修改数量
     * @param goodSkuChecked
     * @param buyNum
     */
    @Override
    public void addShopCarUpdateNum(Integer goodSkuChecked, Integer buyNum) {
        systemMapper.addShopCarUpdateNum(goodSkuChecked,buyNum);
    }
}
